const path = require('path');
// const miniCSSExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
    entry: path.join(__dirname, 'index.js'),
    output: {
        filename: 'bundle__[chunkhash:6].js',
        path: path.join(__dirname, 'dist')
    },
    module: {
        rules: [{
            test: /\.styl$/,
            // use: [miniCSSExtractPlugin.loader, 'css-loader', 'stylus-loader']// 提取css文件
            use: ["style-loader",'css-loader', 'stylus-loader']// 不提取css文件，采用插入头部
        }, {
            test: /\.png$/,
            use: [{
                loader: 'file-loader',
                options: {
                    // name是名字占位符，ext是资源后缀名占位符，冒号含义是取几位
                    name: '[name]__[contenthash:6].[ext]'
                }
            }]
        }]
    },
    plugins: [
        new CleanWebpackPlugin(),// 每次构建完成清除dist目录
        // new miniCSSExtractPlugin({
        //     filename:'[name]__[contenthash:6].css'
        // })
    ],
    mode: "production"
};